<%@ page language="java" import="java.util.*,com.css.vo.*" pageEncoding="UTF-8"%>
<%@ page import="com.css.dao.*,com.css.dao.impl.*"%>
<%@ page import="com.css.dao.*,com.css.action.*"%>
<%@ page import="com.css.dao.*,com.css.service.*"%>
<%@ page import="org.springframework.context.*,org.springframework.context.support.*"%>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>修改客户信息</title>
  <link rel="stylesheet" href="./../styles.css">
</head>
<body>
  <header>
    <h1>修改客户信息</h1>
    <nav>
      <ul> 
      	<li><a href="./../index.jsp">主页</a></li>
        <li><a href="getList.action">系统管理</a></li>
        <li><a href="../Customer/customer-management.jsp">客户信息管理</a></li>
        <li><a href="../Car/car-management.jsp">汽车信息管理</a></li>
        <li><a href="../Employee/employee-management.jsp">员工信息管理</a></li>
        <li><a href="../Sale/sales-management.jsp">销售信息管理</a></li>
      </ul>
    </nav>
  </header>
  
  <%
  
  	ApplicationContext myaApplicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
    ICarService carService = (ICarService) myaApplicationContext.getBean("carService");
    ICustomerService customerService = (ICustomerService) myaApplicationContext.getBean("customerService");
    
    int customerId = Integer.parseInt(request.getParameter("customerId"));
    Customer customer = customerService.findById(customerId);
    Car car = carService.findById(customer.getIntention());
   %>

  <div class="content">
    <h2>请输入客户信息</h2>
<form action="updateCustomer.action" method="post">
    <input type="hidden" id="customer.customerId" name="customer.customerId" value="${customer.customerId}">
    <label for="customerName">姓名</label>
    <input type="text" id="customer.customerName" name="customer.customerName" value="${customer.customerName}" required><br>

    <label for="version">性别</label>
    <input type="text" id="customer.gender" name="customer.gender" value="${customer.gender}" required><br>

    <label for="birthDate">生日</label>
    <input type="date" id="customer.birthDate" name="customer.birthDate" value="${customer.birthDate}" required><br>

    <label for="phone">电话</label>
    <input type="text" id="customer.phone" name="customer.phone" value="${customer.phone}" required><br>

    <label for="address">地址</label>
    <input type="text" id="customer.address" name="customer.address" value="${customer.address}" required><br>

    <label for="car">汽车：</label>
      <select id="sale.carId" name="sale.carId" required>
        <option value="">请选择汽车</option>
        <% 
          List<Car> carList = carService.findAllCar();
          for (Car cars : carList) {
        %>
          <option value="<%= cars.getCarId() %>" <%= (cars.getCarId().equals(customer.getIntention()) ? "selected" : "") %>>
            <%= cars.getCarModel() + " " + cars.getVersion() + " " + cars.getYear() + "款" + " " + cars.getColor() %>
          </option>
        <% 
          }
        %>
      </select><br>


    <button type="submit">提交</button>
</form>

  </div>
</body>
</html>
